<template>
  <cate-search-bar></cate-search-bar>
  <checkout
    :type="type"
    :addresses="addresses"
    :cartItems="cartItems"
  ></checkout>
</template>
<script>
import { mapGetters } from "vuex";
import Checkout from "../components/Checkout.vue";
import CateSearchBar from "../components/CateSearchBar.vue";
export default {
  data() {
    return {
      cartItems: [],
    };
  },
  computed: {
    ...mapGetters({ addresses: "user/addresses" }),
  },
  components: {
    Checkout,
    CateSearchBar,
  },
  created() {
    if (this.addresses.length == 0) {
      this.$store.dispatch("user/fetchUserAddress");
    }
    this.type = this.$route.params.type;
    if (this.type == "now") {
      this.cartItems = this.$store.getters["order/buyNow"]; //('order/buyNow');
    } else {
      this.cartItems = this.$store.getters["order/cartItems"];
    }
  },
};
</script>